// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx fmt::format, 自定义 fmt 打印形式

#define MyFPrt(...) spdlog::info(__VA_ARGS__)
// macro 二次传递参数, 不要用 ##__VA_ARGS__
#define MyFPrtln(...) spdlog::info(__VA_ARGS__);

#define MyFPrt2(...) spdlog::warn(__VA_ARGS__)
#define MyFPrt2ln(...) spdlog::warn(__VA_ARGS__);
#define MyFPrtEln(...) spdlog::error(__VA_ARGS__);

//----------------------
#if 0
#define MYINFO(...)                  \
    fmt::print(MY_CLR_FG_BL_STRING); \
    fmt::print(__VA_ARGS__);         \
    fmt::print(MY_CLR_FG_RESET_STRING);

#define MYINFOLN(...)          \
    ::fmt::print(__VA_ARGS__); \
    ::fmt::print("\n");
#endif

// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx raw implement, log with line number
#define __MyLog(...)         \
    do                       \
    {                        \
        printf(__VA_ARGS__); \
    } while (0)

#define __format(__fmt__) "%d:%s: " __fmt__ "\n"

#define MyLog(__fmt__, ...)                                              \
    do                                                                   \
    {                                                                    \
        __MyLog(__format(__fmt__), __LINE__, __FUNCTION__, __VA_ARGS__); \
    } while (0)

//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx c++ 20, 打印 std::optional
// 重载 std::optional 的 operator<<
#if 0
//----------------------- 特化 fmt::ostream_formatter, 使用 operator<< 打印
#define MY_FMT_OS_FMTTER(type)                           \
    template <>                                          \
    struct fmt::formatter<type> : fmt::ostream_formatter \
    {                                                    \
    };
#endif

#if 0
template <typename T>
::std::ostream& operator<<(::std::ostream& out, ::std::optional<T> const& opt)
{
    if (!opt)
    {
        MyfPrt("None");
        return out;
    }
    out << "Some(" << opt.value() << ")";
    return out;
}
#endif

//------------------ 显式实例化定义
#if 0
template ::std::ostream& operator<<(::std::ostream&, ::std::optional<int> const&);
template ::std::ostream& operator<<(::std::ostream&, ::std::optional<::std::string> const&);
#endif

//------------------ 显式特化
#if 0
MY_FMT_OS_FMTTER(std::optional<int>);                //
MY_FMT_OS_FMTTER(std::optional<std::string>);        //
MY_FMT_OS_FMTTER(std::optional<std::vector<char>>);  //
MY_FMT_OS_FMTTER(std::optional<std::vector<int>>);   //
#endif

//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 自定义 std::vector 打印格式;
// 可以使用 format/ranges 代替
#if 0
template <typename T>
void myPrtArr(const ::std:: vector<T>& v)
{
    if (v.empty())
    {
        MyfPrt("[ ]");
        return;
    }

    MyfPrt("[ ");
    for (size_t i = 0; i < v.size() - 1; i++) MyfPrt("{}, ", i);
    MyfPrt("{} ]", v.back());
}
//
template <typename T>
void myPrtArrln(const ::std:: vector<T>& v)
{
    myPrtArr(v);
    ::std:: cout << ::std:: endl;
}
#endif

//========================== 重载 std::vector 的 operator<<
#if 0
template <typename T>
::std::ostream& operator<<(::std::ostream& out, ::std::vector<T> const& v)
{
    if (v.empty())
    {
        MyfPrt("[ ]");
        return out;
    }
    out << "[ ";
    ::std::copy(v.begin(), v.end() - 1, ::std::ostream_iterator<T>(out, ", "));
    out << v.back() << " ]";
    return out;
}
#endif